package org.dromara.system.controller.system;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SimUserPurseBo;
import org.dromara.system.domain.bo.SimUserPurseRecordsBo;
import org.dromara.system.domain.vo.SimUserPurseRecordsVo;
import org.dromara.system.service.ISimUserPurseRecordsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户钱包记录
 *
 * @author Lion Li
 * @date 2025-08-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userPurseRecords")
public class SimUserPurseRecordsController extends BaseController {

    private final ISimUserPurseRecordsService simUserPurseRecordsService;

    /**
     * 查询用户钱包记录列表
     */
//    @SaCheckPermission("system:userPurseRecords:list")
    @GetMapping("/list")
    public TableDataInfo<SimUserPurseRecordsVo> list(SimUserPurseRecordsBo bo, PageQuery pageQuery) {
        return simUserPurseRecordsService.queryPageList(bo, pageQuery);
    }


    @GetMapping("/listReception")
    public TableDataInfo<SimUserPurseRecordsVo> listReception(SimUserPurseRecordsBo bo, PageQuery pageQuery) {
        return simUserPurseRecordsService.listReception(bo, pageQuery);
    }

    /**
     * 导出用户钱包记录列表
     */
//    @SaCheckPermission("system:userPurseRecords:export")
    @Log(title = "用户钱包记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SimUserPurseRecordsBo bo, HttpServletResponse response) {
        List<SimUserPurseRecordsVo> list = simUserPurseRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户钱包记录", SimUserPurseRecordsVo.class, response);
    }

    /**
     * 获取用户钱包记录详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userPurseRecords:query")
    @GetMapping("/{id}")
    public R<SimUserPurseRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(simUserPurseRecordsService.queryById(id));
    }

    /**
     * 新增用户钱包记录
     */
//    @SaCheckPermission("system:userPurseRecords:add")
    @Log(title = "用户钱包记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SimUserPurseRecordsBo bo) {
        return toAjax(simUserPurseRecordsService.insertByBo(bo));
    }

    /**
     * 修改用户钱包记录
     */
//    @SaCheckPermission("system:userPurseRecords:edit")
    @Log(title = "用户钱包记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SimUserPurseRecordsBo bo) {
        return toAjax(simUserPurseRecordsService.updateByBo(bo));
    }

    /**
     * 删除用户钱包记录
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userPurseRecords:remove")
    @Log(title = "用户钱包记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(simUserPurseRecordsService.deleteWithValidByIds(List.of(ids), true));
    }

    //    @SaCheckPermission("system:userPointsRecords:updateUserFreezePoints")
    @Log(title = "修改钱包", businessType = BusinessType.INSERT)
    @PostMapping("/updateUserPurse")
    public R<Boolean> updateUserPurse(@RequestBody List<SimUserPurseBo> boList) {
        return R.ok(simUserPurseRecordsService.updateUserPurse(boList));
    }

}
